//
//  GLHero.m
//  QAQ打飞机
//
//  Created by admin on 15/8/28.
//  Copyright (c) 2015年 gl. All rights reserved.
//

#import "GLHero.h"
#import "GLBullet.h"
#define kBulletCount 2
@implementation GLHero
-(id)initWithArea:(CGRect)gameArea size:(CGSize)heroSize
{
    self =[super init];
    if (self !=nil) {
        CGFloat x =gameArea.size.width/2.0f;
        
        //相当于留出自身高度的一半
        CGFloat y =gameArea.size.height -heroSize.height;
        self.position =CGPointMake(x, y);
        self.size =heroSize;
        self.bombCount = 0;
        self.bEnhanced = NO;
        self.enhancedTime = 0;
        
        //初始化子弹集合
        self.heroBulletSet =[NSMutableSet set];
    }
    return self;
}
#pragma mark -一次发射三颗子弹
-(void)fire3Bullet
{
    CGSize bulletSize =self.normalBulletSize;
    if (self.bEnhanced) {
        bulletSize = self.enhancedBulletSize;
    }
    CGFloat x =self.position.x;
    CGFloat y =self.position.y-self.size.height/2.0-bulletSize.height/2.0;
    for (NSInteger i=0; i<kBulletCount; i++) {
        GLBullet *b =[GLBullet bulletWithPosition:CGPointMake(x, y-i*2*bulletSize.height) size:bulletSize enhanced:self.bEnhanced];
        //添加到子弹集合
        [self.heroBulletSet addObject:b];
    }

}
#pragma mark -英雄碰撞检测边框的getter
-(CGRect)collisionFrame
{
    CGFloat x =self.position.x-self.size.width/4.0;
    CGFloat y=self.position.y-self.size.height/2.0;
    CGFloat w=self.size.width/2.0;
    CGFloat h =self.size.height;
    return CGRectMake(x, y, w, h);
}
@end
